<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>set</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="__STATIC__/xadmin/css/font.css">
    <link rel="stylesheet" href="__STATIC__/xadmin/css/xadmin.css">
    <script type="text/javascript" src="__STATIC__/xadmin/lib/layui/layui.js?v=1.0.2" charset="utf-8"></script>
    <script type="text/javascript" src="__STATIC__/xadmin/js/xadmin.js"></script>
    <script type="text/javascript" src="__STATIC__/xadmin/js/jquery.min.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form layui-form-pane">
            <div class="layui-form-item">
                <label class="layui-form-label">选择套餐</label>
                <div class="layui-input-block">
                    <select name="tc_id" lay-filter="taocan">
                        {volist name="taocanList" id="vtc"}
                            <option {if $list['tc_id']==$vtc['id']} selected{/if} value="{$vtc['id']}"> {$vtc['title']}---$ {$vtc['dollar']}---￥ {$vtc['price']}</option>
                        {/volist}
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">选择类型</label>
                <div class="layui-input-inline">
                    <select name="type" lay-filter="demo" >
                        {volist name="typeList" id="vt"}
                        <option {if $list.type==$key} selected{/if} value="{$key}">{$vt}</option>
                        {/volist}
                    </select>
                </div>
                <label class="layui-form-label">选择使用范围</label>
                <div class="layui-input-inline">
                    <select name="range" id="">
                        {volist name="rangeList" id="vr"}
                        <option {if $list['range']==$key} selected{/if} value="{$key}">{$vr}</option>
                        {/volist}
                    </select>
                </div>
            </div>
            <div class="layui-form-item type" id="type1" style="display:none;">
                <label class="layui-form-label">抵用金额</label>
                <div class="layui-input-inline">
                    <input type="text" name="di" class="layui-input" value="{$list.di|default=0.00}">
                </div>
            </div>
            <div class="layui-form-item type" id="type2" style="display: none">
                <label class="layui-form-label">折扣百分比</label>
                <div class="layui-input-inline">
                    <input type="text" name="zhe" class="layui-input" value="{$list.zhe|default=0}">
                </div>
            </div>
            <div class="layui-form-item type" id="type3" style="display: none">
                <label class="layui-form-label">满减的满</label>
                <div class="layui-input-inline">
                    <input type="text" name="man" class="layui-input" value="{$list.man|default=0.00}">
                </div>
                <label class="layui-form-label">满减的减</label>
                <div class="layui-input-inline">
                    <input type="text" name="jian" class="layui-input" value="{$list.jian|default=0.00}">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">开始时间</label>
                <div class="layui-input-inline">
                    <input type="text" id="starttime" name="starttime" value="{$list['starttime']?date('Y-m-d H:i:s',$list['starttime']):'';}" class="layui-input">
                </div>
                <label class="layui-form-label">失效时间</label>
                <div class="layui-input-inline">
                    <input type="text" id="endtime" name="endtime" value="{$list['endtime']?date('Y-m-d H:i:s',$list['endtime']):'';}" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">可用次数</label>
                <div class="layui-input-inline">
                    <input type="text"  name="num" value="{$list['num']|default=1}" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <button class="layui-btn" lay-filter="add" lay-submit="">确认</button>
            </div>
        </form>
    </div>
</div>
</body>
<script>
    $(function () {
        var type="{$list.type}";
        if(!type){
            type=1;
        }
        console.log(type);
        // $('#'+typeid).show();
        var typeid="#type"+type;
        console.log(typeid);
        $(typeid).show();
    })

    layui.use(['form', 'layer','laydate'], function () {
        $ = layui.jquery;
        var form = layui.form
            , layer = layui.layer
        ,laydate=layui.laydate;

        laydate.render({
            elem:"#starttime"
        })
        laydate.render({
            elem:"#endtime"
        })

        form.on("select(demo)",function(data){
            console.log(data.value);
            var val=data.value;
            var tid="type"+val;
            $('.type').hide();
            $('#'+tid).show();
        })
        //监听提交
        form.on('submit(add)', function (data) {
            var ids="{$list['id']|default=0}";
            $.ajax({
                type: "post",
                url: "{:url('addCoupon');}",
                data: {
                    type:data.field.type,
                    tc_id:data.field.tc_id,
                    id:ids,
                    starttime:data.field.starttime,
                    endtime:data.field.endtime,
                    range:data.field.range,
                    num:data.field.num,
                    di:data.field.di,
                    zhe:data.field.zhe,
                    man:data.field.man,
                    jian:data.field.jian,
                },
                success: function (data) {
                    if (data.status == 1) {
                        layui.use('layer', function () {
                            var layer = layui.layer;
                            layer.msg('添加成功!', {icon: 1, time: 1000});
                            setTimeout(function () {
                                parent.location.href = "{:url('Tools/coupon');}";
                            }, 1000);
                        });
                    } else {
                        layui.use('layer', function () {
                            var layer = layui.layer;
                            layer.msg(data.message, {
                                time: 2000
                            });
                        });
                    }
                }
            });
            return false;
        });
    });
    function showNext(){
        console.log($(this));
    }

</script>
</html>